﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using School.Entities;
using System.Collections;
using System.IO;

namespace School.Organization
{
    public static class Campus
    {
        private static SchoolEntities db = new SchoolEntities();

        public static void Add(ORG_Campus campus)
        {
            db.AddToORG_Campus(campus);
            db.SaveChanges();
        }

        public static ORG_Campus Single(long id)
        {
            return db.ORG_Campus.Single(x => x.Id == id);
        }


        public static IQueryable<ORG_Campus> All()
        {           
            var query = from campus in db.ORG_Campus select campus;

            return query;
        }
        public static string getCamp_Cod(int cam_id)
        {
            return ((from c in db.ORG_Campus where c.Id == cam_id select c.Code).FirstOrDefault());
        }


        public static void Update(ORG_Campus campus)
        {
            ORG_Campus c = db.ORG_Campus.Single(x => x.Id == campus.Id);
            c.Id = campus.Id;
            c.Name = campus.Name;
            c.Code = campus.Code;
            c.Description = campus.Description;

            db.SaveChanges();

        }

        public static Boolean Delete(long id)
        {
            try
            {
                db.ORG_Campus.DeleteObject(db.ORG_Campus.Single(x => x.Id == id));
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }


    }
}
